package com.aiit.controller.user;

import com.aiit.dto.UserBookingDTO;
import com.aiit.entity.Booking;
import com.aiit.result.Result;
import com.aiit.service.BookingService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/booking")
@Slf4j
@Api(tags = "客户端：订座相关接口")
public class BookingController2 {
    @Autowired
    private BookingService bookingService;

    /**
     * 条件查询
     *
     * @param
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "bookingCache2", key = "#id != null ? #id : 'default_id'")//key : setmealCche::100
    public Result<List<Booking>> list(Long id) {
        Booking booking = new Booking();
        Booking.setid(id);

        System.out.println("已完成用户查询");

        List<Booking> list = bookingService.list(booking);
        return Result.success(list);
    }

    @PostMapping("/order/booking")
    @ApiOperation("订单插入")
    public Result save(@RequestBody UserBookingDTO userBookingDTO, @RequestParam String username) {
        log.info("订单插入：{}");
        userBookingDTO.setUsername(username);
//        userBookingDTO.setSession_time(session_time);
        System.out.println("当前线程的id:" + Thread.currentThread().getId());
        bookingService.savebookings(userBookingDTO);
        return Result.success();
    }

    @GetMapping("/selectByUsername")
    @ApiOperation("会员订单查询")
    public Result<Page<UserBookingDTO>> orders(UserBookingDTO userBookingDTO) {
        Page<UserBookingDTO> orderResult = bookingService.userBooking(userBookingDTO);
        return Result.success(orderResult);
    }
}
